<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var el = console.log;
        let myMap = new Map()
        let keyObj = {}
        let keyFunc = function () {}
        let keyStr = "a string"

        // 添加键名
        myMap.set(keyStr, "和键'a string'关联的值");
        myMap.set(keyObj, "和键keyObj关联的值");
        myMap.set(keyFunc, "和键keyFunc关联的值");

        el(myMap)

        el(myMap.get(keyObj))

        // 使用Nan作为键名
        let keyNaN = NaN
        myMap.set(keyNaN, 'not a number')

        // 获取
        el(myMap.get(NaN))
        // 上下两式子相同
        el('我是number()强转得到的值: ' + myMap.get(Number("lalala")))

        // 使用for..of方法迭代Map数据类型
        for (let [key, value] of myMap.entries()) {
            if (typeof key == 'function') {
                el(value)
            }
        }

        // 使用二维数组定义Map对象
        let d2Arr = [
            ["key1", "value1"],
            ["key2", "value2"]
        ];
        let arrMap = new Map(d2Arr)

        arrMap.forEach(function(key, value) {
            el(key + '----' + value)
        })
    </script>
</head>

<body>

</body>

</html>